package personal.hrsw.mybatisplusdemo.mapper;

import org.apache.ibatis.annotations.*;
import personal.hrsw.mybatisplusdemo.domain.Student;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
* @author Administrator
* @description 针对表【student】的数据库操作Mapper
* @createDate 2025-04-24 09:27:24
* @Entity personal.hrsw.mybatisplusdemo.domain.Student
*/
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
    @Select("select * from student ")
    List<Student> selectAll();
    @Delete("delete from student where id=#{id}")
    public int deleteById(int id);
    @Insert("insert into student(name,password,sex,clazz,birthday) values (#{name},#{password},#{sex},#{clazz},#{birthday})")
    int insert(Student student);
    @Select("select * from student where id=#{id}")
    Student selectById(int id);
    @Update("update student set name=#{name},password=#{password},sex=#{sex},clazz=#{clazz},birthday=#{birthday} where id=#{id}")
    int update(Student student);
    @Select("select * from student limit #{fromIndex},#{pageSize}")
    @Results({
            @Result(column = "id",property = "id",javaType = Integer.class),
            @Result(column = "id",property = "scores",javaType = List.class,
                    many = @Many(select = "personal.hrsw.mybatisplusdemo.mapper.ScoreMapper.selectByStudentId")
            )
    })
    public List<Student> selectByPage(@Param("fromIndex")int fromIndex, @Param("pageSize")int pageSize);
    //    List<Student> selectByPage(int fromIndex, int pageSize);
    @Select("select * from student where name=#{username} and password=#{password}")
    Student selectByNameAndPwd(String username, String password);
}




